﻿@using CubicFWNet.Data.Models
@model CubicFWNet.Data.Models.Examine
@*@model IEnumerable<ProductTechnologyView>*@
@{
    //ViewBag.Title = "价格核算";
    var techType = ViewBag.TechType as TechType;
    var checkToalLength = ViewBag.CheckToalLength;
    var operationName = ViewBag.OperationName;
    var operationTime = ViewBag.OperationTime;
    var examineNum = ViewBag.ExamineNum;
    var examinetype = ViewBag.Examinetype;
    var applyName = ViewBag.ApplyName;
    var amount = ViewBag.Amount;
    var orderId = ViewBag.OrderId;
    var type = ViewBag.Type;
    var product = ViewBag.Product as CubicFWNet.Data.Models.Product;
}
<section class="content-header">
    <h1>
        检验审核
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("Check", "Examine")">检验查询</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                @if (Model != null && product != null)
                {
                    <form class="form-horizontal" id="frmedit" action="@Url.Action("CompleteExamine", "Examine")" method="post">
                        <div class="box-body">
                            <input type="hidden" id="Id" name="Id" value="@Model.Id" />
                            <input type="hidden" id="Unit" name="Unit" value="@product.Unit" />
                            <input type="hidden" id="PurchaseNameId" name="PurchaseNameId" value="@product.Id" />
                            <input type="hidden" id="orderId" name="orderId" value="@orderId" />
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">检验单编号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Number" name="Number" value="@examineNum" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ProductName" name="ProductName" value="@product.Name" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">类型</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ProductType" name="ProductType" value="@type" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">检验类别</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Type" name="Type" value="@examinetype" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">检验工时-分钟</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" value="@techType.ExamineNum" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">总计工时-分钟</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" value="@checkToalLength" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">实际总计工时-分钟</label>
                                <div class="col-sm-9">
                                    @if (Model.Status == -1)
                                    {
                                        <input type="number" class="form-control" name="RealExamLength" id="RealExamLength" value="" required />
                                    }
                                    else
                                    {
                                        <input type="number" class="form-control" name="RealExamLength" id="RealExamLength" value="@Model.RealExamLength" readonly="readonly" />
                                    }
                                    
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">申请人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ApplyName" name="ApplyName" value="@applyName" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">申请时间</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ApplyTime" name="ApplyTime" value="@Model.ApplyTime" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">申请数量</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control okeydown" id="ProducAmount" name="ProducAmount" value="@amount" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">合格数量</label>
                                <div class="col-sm-9">
                                    @if (Model.Status == -1)
                                    {
                                        <input type="text" class="form-control okeydown" id="StandardAmount" name="StandardAmount" value="" required />
                                    }
                                    else
                                    {
                                        <input type="text" class="form-control okeydown" id="StandardAmount" name="StandardAmount" value="@Model.StandardAmount" readonly="readonly" />
                                    }

                                </div>
                            </div>
                            @*<div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">检验员</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" id="CreatorName" name="CreatorName" value="@operationName" readonly="readonly" />
                                    </div>
                                </div>*@
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">备注</label>
                                <div class="col-sm-9">
                                    @if (Model.Status == -1)
                                    {
                                        <textarea class="form-control" rows="3" name="Memo" id="Memo"></textarea>
                                    }
                                    else
                                    {
                                        <textarea class="form-control" rows="3" name="Memo" id="Memo" readonly="readonly">@Model.Memo</textarea>
                                    }
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label for="operationName" class="col-sm-3 control-label">操作人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationName" name="operationName" value="@operationName" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationTime" class="col-sm-3 control-label">日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationTime" name="operationTime" value="@operationTime" readonly="readonly">
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="width: 80%; margin-left: 20px;">
                            @if (Model.Status == -1)
                            {
                                <a role="button" href="javascript:void(0)" id="submitId" class="btn btn-primary submitbtn" onclick="formsubmit(1)">通过</a>
                            }
                            <span id="historyBack" class="btn btn-primary submitbtn">返回</span>
                            @*<a role="button" href="@Url.Action("Check", "Examine")" class=" btn btn-primary submitbtn">返回</a>*@
                            <div class="text-red" style="margin-top:20px;font-weight:bold">下一步：库房管理-->产品入库申请</div>
                        </div>
                    </form>
                }
            </div>
        </div>
    </div>
</section>
<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

<style>
    .has-error {
        border-color: #dd4b39;
        box-shadow: none;
    }
</style>


@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            //日期控件
            $(".Timedatepicker").datepicker({
                autoclose: true,
                language: 'zh', //汉化
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                minView: "month" //选择日期后，不会再跳转去选择时分秒
            });


            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            $.modalAlert("操作成功", "success");
                            window.location.href = '@Url.Action("Check", "Examine")';
                        }
                    });
                }
            });
        });

        function formsubmit(t) {
            var a = $("#ProducAmount").val();//申请数量
            var b = $("#StandardAmount").val();//合格数量
            var realExamLength = $("#RealExamLength").val();
            if (realExamLength == "" || isNaN(realExamLength)) {
                $.modalAlert("总工时填写有误", "warning");
                return;
            }
            if (a == "" || isNaN(a)) {
                $.modalAlert("申请数量格式错误", "warning");
                return;
            }
            if (b == "" || isNaN(b)) {
                $.modalAlert("合格数量格式错误", "warning");
                return;
            }
            if ((b / 1) <= 0) {
                $.modalAlert("合格数量不可为0", "warning");
                return;
            }
            
            /*if (a / 1 < b / 1) {
                $.modalAlert("合格数量不能大于申请数量", "warning");
                return;
            }*/
            top.layer.confirm('本次质检数量' + b, {
                icon: "fa-exclamation-circle",
                title: "系统提示",
                btn: ['确认', '取消'],
                btnclass: ['btn btn-primary', 'btn btn-danger']
            }, function () {
                $("#submitId").attr('disabled', "true");
                $("#frmedit").submit();
            }, function () {

            });
        }

        $(".okeydown").on("keyup", function () {
            var value = $(this).val();
            if (isNaN(value) || value == "" || value == "Infinity" || value == "NaN") {
                $(this).addClass("has-error");
            } else {
                $(this).removeClass("has-error");
            }
        });


        $(".okeydown").on("keydown", function () {
            var k = event.keyCode;
            if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                return true;
            } else {
                return false;
            }
        });

        $("#historyBack").click(function () {
            window.history.go(-1);  //返回上一页
            //window.history.back();  //返回上一页
        });
    </script>
}